<template>
  <div class='questions-preview'>
    <!-- 预览对话框 -->
    <el-dialog title="题目预览" :visible.sync="dialogVisible" @close="close"  width="55%">
        <el-row>
          <el-col :span="6">【题型】：{{myData.questionType | type}}</el-col>
          <el-col :span="6">【编号】：{{myData.id}}</el-col>
          <el-col :span="6">【难度】：{{myData.difficulty | difficult}}</el-col>
          <el-col :span="6">【标签】：{{myData.tags}}</el-col>
          <el-col :span="6">【学科】：{{myData.subjectName}}</el-col>
          <el-col :span="6">【目录】：{{myData.directoryName}}</el-col>
          <el-col :span="6">【方向】：{{myData.direction}}</el-col>
        </el-row>
        <hr>
        【题干】：<div style="color:blue" v-html="myData.question"></div>
          <div v-if="myData.questionType !== '3'">
            <div>{{myData.questionType | type}}选项：(以下选中的选项为正确答案)</div>
            <div v-for="item in myData.options" :key="item.code" style="padding:10px 0">
              <el-radio v-if="myData.questionType === '1'" :value="item.isRight" :label="1">{{item.title}}</el-radio>
              <el-checkbox v-if="myData.questionType === '2'" :value="item.isRight?true:false">{{item.title}}</el-checkbox>
            </div>
          </div>
        <hr>
        【参考答案】：<el-button type="danger" size="small" @click="previewAnswer()">视频答案预览</el-button>
          <div v-show="play" class="video">
             <video ref="video" :src="myData.videoURL" controls muted></video>
          </div>
        <hr>
        【答案解析】：<div v-html="myData.answer" style="display:inline-block"></div>
        <hr>
        【题目备注】：{{myData.remarks}}
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="dialogVisible = false">关闭</el-button>
        </span>
    </el-dialog>
  </div>
</template>

<script>
import { detail as questionsDetail } from '@/api/hmmm/questions.js'
import { questionType, difficulty } from '@/api/hmmm/constants.js'
export default {
  name: 'questions-preview',
  props: {
    data: {
      type: Object,
      default: () => {}
    }
  },
  data () {
    return {
      dialogVisible: false,
      myData: {},
      play: false
    }
  },
  methods: {
    async open () {
      const res = await questionsDetail({ id: this.data.id })
      console.log(res)
      this.myData = res.data
      this.dialogVisible = true
    },
    // 预览
    previewAnswer () {
      this.play = true
      this.$refs.video.play()
    },
    close () {
      this.play = false
      this.$refs.video.pause()
    }
  },
  filters: {
    type (value) {
      if (value) return questionType.find(item => item.value === +value).label + '题'
    },
    difficult (value) {
      if (value) return difficulty.find(item => item.value === +value).label
    }
  }
}
</script>

<style scoped lang='scss'>
.questions-preview{
  .el-col{
    padding: 10px 0;
  }
}

.video{
  width: 300px;
  height: 240px;

  video{
    width: 400px;
    height: 240px;
  }
}
</style>
